package remote.layouts
{
	import flash.display.DisplayObject;
	import flash.geom.Rectangle;
	
	import remote.controls.Component;
	import remote.geom.EdgeMetrics;
	import remote.utils.DisplayObjectUtil;
	
	
	/**
	 * 绝对布局
	 * @author 银魂飞雪
	 * @createDate 2011-2-27
	 */
	public class AbsoluteLayout extends LayoutBase implements ILayout
	{
		public function AbsoluteLayout(target:Component = null)
		{
			super(target);
		}
		
		public function layout():void
		{
		}
		
		public function get edge():EdgeMetrics
		{
			return new EdgeMetrics();
		}
		
		public function get contentRect():Rectangle
		{
			return new Rectangle(0, 0, target.width, target.height);
		}
		
		public function get childrenRect():Rectangle
		{
			if(elements.length == 0)
				return new Rectangle();
			var result:Rectangle = new Rectangle(elements[0].x, elements[0].y, elements[0].width, elements[0].height);
			for(var i:int = 1; i < elements.length; i++)
			{
				var child:DisplayObject = elements[i];
				if(child.x < result.left)
					result.left = child.x;
				if(child.x + child.width > result.right)
					result.right = child.x + child.width;
				if(child.y < result.top)
					result.top = child.y;
				if(child.y + child.height > result.bottom)
					result.bottom = child.y + child.height;
			}
			return result;
		}
	}
}